package com.hqyj.springtest.mapper.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.hqyj.springtest.pojo.SysUser;
import com.hqyj.springtest.util.JWTUtil;

import io.jsonwebtoken.Claims;

public class LoginIntercepter extends HandlerInterceptorAdapter{

	@Autowired
	JWTUtil js;
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// ��ȡheaders�е�����
		 String token =   request.getHeader("token");
		 System.out.println("token" +  token);
		 Claims parseToken = js.parseToken(token);
		 Object object = parseToken.get("user");
		 if(object != null) {
			 SysUser user = (SysUser)object;
			 return true;
		 }else {
			 response.sendRedirect("html/index.html");
			 return false;
		 }
		/*
		 String token =  request.getHeader("login");
		 if("login_success".equals(token)) {
		     return true;
		 }
		 response.sendRedirect("html/index.html");
		 return false;
		 */
	}
}
